package com.cabrida.livestar.main;

import java.util.ArrayList;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cabrida.livestar.R;
import com.cabrida.livestar.model.FansLiveListData;
import com.cabrida.livestar.util.MyUtils;

/**
 * 首页直播adapter
 * 
 * @author why
 * 
 */
public class FansHomePageLiveAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private ArrayList<FansLiveListData> data_list = new ArrayList<FansLiveListData>();

	public FansHomePageLiveAdapter(Context context) {
		this.mInflater = LayoutInflater.from(context);
	}

	public void setData(ArrayList<FansLiveListData> data) {
		data_list = data;
	}

	@Override
	public int getCount() {
		return data_list.size();
	}

	@Override
	public FansLiveListData getItem(int arg0) {
		return data_list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {

			holder = new ViewHolder();

			convertView = mInflater.inflate(R.layout.adapter_homepage_gv_live_item,
					null);
			holder.iv_image = (ImageView) convertView.findViewById(R.id.iv_image);
			holder.tv_nickname = (TextView) convertView.findViewById(R.id.tv_nickname);
			holder.tv_click = (TextView) convertView.findViewById(R.id.tv_click);
			holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}
		MyUtils.loadImg(data_list.get(position).getS_image(), holder.iv_image);
		String ss_time = data_list.get(position).getL_createtime();
		if (!TextUtils.isEmpty(ss_time)&&ss_time.contains(":")) {
			String[] strs = ss_time.split(":");
			if (strs.length>=2) {
				holder.tv_time.setText("已开播"+strs[0]+"小时"+strs[1]+"分");
			}
		}
		holder.tv_nickname.setText(data_list.get(position).getS_name().toString());
		holder.tv_click.setText(data_list.get(position).getL_click().toString());

		return convertView;
	}

	class ViewHolder {
		private ImageView iv_image;
		private TextView tv_nickname;
		private TextView tv_click;
		private TextView tv_time;
	}
}
